package com.demo455_分发饼干;

import java.util.Arrays;

public class Solution {
    // g 是孩子的胃口, s  是饼干的尺寸
    public int findContentChildren(int[] g, int[] s) {
        //1.对两个数组进行排序
        Arrays.sort(g);
        Arrays.sort(s);
        //2.分别用两个指针指向饼干,以及孩子
        int cookie = 0;
        int child = 0;
        int count = 0;
        while (child < g.length && cookie < s.length) {
            if (s[cookie] >= g[child]) {
                child++;
                cookie++;
                count++;
            } else {
                cookie++;
            }
        }
        return count;
    }
}
